package com.example.shop_front_api.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.shop_front_api.entity.Product;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface ProductMapper extends BaseMapper<Product> {

    @Update("update shop_products set stock = stock - #{quantity}, sales = sales + #{quantity} where id = #{productId} and stock >= #{quantity}")
    int updateStock(@Param("productId") Integer productId, @Param("quantity") Integer quantity);

    @Update("update shop_products set lock_stock = lock_stock + #{lockStock} where id = #{productId}")
    int updateLockStock(@Param("productId") Integer productId, @Param("lockStock") Integer lockStock);
}